package com.firewolf.rbac.controller;

import com.firewolf.rbac.params.RoleParam;
import com.firewolf.rbac.pojo.Role;
import com.firewolf.rbac.service.RoleService;
import com.firewolf.rbac.vo.PageVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 作者：刘兴
 * 时间:19/2/28
 **/
@RestController
@RequestMapping("/role")
public class RoleController {

    @Autowired
    private RoleService roleService;

    /**
     * 查询所有角色
     *
     * @return
     */
    @GetMapping("/all")
    public List<Role> findAll() {
        return roleService.findAll();
    }

    /**
     * 带条件查询
     *
     * @return
     */
    @GetMapping("/list")
    public PageVO<Role> findList(RoleParam param) {
        return roleService.findList(param);
    }

    /**
     * 添加或者是修改用户
     *
     * @return
     */
    @PostMapping
    public Long saveRole(Role role) {
        Long id = roleService.save(role);
        return id;
    }

    /**
     * 根据角色ID查询菜单
     *
     * @param roleId
     * @return
     */
    @GetMapping("/menus/{roleId}")
    public List<Long> menus(@PathVariable("roleId") Long roleId) {
        return roleService.findMenusByRoleId(roleId);
    }


    @PostMapping("/editmenus")
    public Integer editmenus(Long id, String menuids) {

        roleService.editmenus(id, menuids);
        return 1;
    }
}
